include( "shared.lua" )

ENT.TargetIDName = "EQUIPMENT ARMORY"

--[[local MenuFont = Font( "Default", 36 )

local function RayPlaneIntersectionPoint (lineStart, lineEnd, planeNormal, planePos)
	local t = (planeNormal:DotProduct (planePos - lineStart)) / (planeNormal:DotProduct (lineEnd - lineStart))
	local vecIntersect = lineStart + t * (lineEnd - lineStart)
	return vecIntersect
end

local point = RayPlaneIntersectionPoint (Vector (-50, 0, 0), Vector (50, 0, 0), Vector (1,0,0), Vector (0,0,0))

function ENT:Get3DPointOnPlane (point, planeNormal, planePos)
	local p, a = self:GetPos(), self:GetAngles()
	self:SetPos( planePos )
	self:SetAngles( planeNormal )
	
	local returnPoint = self:WorldToLocal( point )
	
	self:SetPos( p )
	self:SetAngles( a )
	
	return returnPoint
end

ENT.LocalPlanePos = Vector (0,0,50)
ENT.LocalPlaneAng = Angle (0,90,90)

ENT.Scale = 0.1
ENT.PlaneWidth = 800
ENT.PlaneHeight = 500

ENT.CursorPos = Vector (0,0,0)

function ENT:Draw()
	self.Entity:SetRenderBounds (self.Entity:OBBMins(), self.Entity:OBBMaxs() + Vector (0,0,75))
	
	self:DrawModel()
		
	local pos = self.Entity:LocalToWorld (self.LocalPlanePos)
	local ang = self.Entity:GetAngles() + self.LocalPlaneAng
	
	self:CalculateCursor(pos, ang:Up())
	
	cam.Start3D2D (pos, ang, self.Scale)
		draw.RoundedBox(
			4,
			self.PlaneWidth *-0.5, self.PlaneHeight *-0.5,
			self.PlaneWidth, self.PlaneHeight,
			Color( 0, 0, 0, 200 )
		)
		draw.SimpleText(
			tostring(self.vecIntersect),
			MenuFont,
			0, 0,
			Color (255,255,255,255),
			TEXT_ALIGN_CENTER
		)
		surface.SetDrawColor (200,200,200,255)
		surface.DrawRect (self.CursorPos.x - 1, self.CursorPos.y - 1, 3, 3)
	cam.End3D2D()
end

function ENT:CalculateCursor (planePos, planeNormal)
	local lineStart = LocalPlayer():GetShootPos()
	local lineEnd = LocalPlayer():GetShootPos() + LocalPlayer():GetAimVector() * 64
	self.vecIntersect = RayPlaneIntersectionPoint (lineStart, lineEnd, planeNormal, planePos)
	self.CursorPos = self:Get3DPointOnPlane (self.vecIntersect, planeNormal:Angle(), planePos) / self.Scale * -1
	self.CursorPos.y = self.CursorPos.z
	self.CursorPos.z = 0
end
]]